package com.xuef.async;

import com.alibaba.fastjson.JSON;
import com.xuef.util.JedisAdapter;
import com.xuef.util.RedisKeyGenerateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by moveb on 2018/5/22.
 */
@Service
public class EventProducer {
    private static final Logger logger = LoggerFactory.getLogger(EventProducer.class);
    @Autowired
    private JedisAdapter jedisAdapter;

    public boolean fireEvent(EventModel eventModel){
        try{
            // 将事件放入队列
            String objJson = JSON.toJSONString(eventModel);
            String key = RedisKeyGenerateUtil.getEventQueueKey();
            jedisAdapter.lpush(key, objJson);
            return true;
        }catch(Exception e){
            logger.info("fireEvent 异常");
            return false;
        }
    }
}
